# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-syntax
pkgver=1.2.2
pkgrel=1
pkgdesc='Ruby library for performing simple syntax highlighting'
arch=(any)
url='https://github.com/dblock/syntax'
license=(BSD)
depends=(ruby)
makedepends=(ruby-rake ruby-rake-contrib ruby-test-unit)
options=(!emptydirs)
source=(https://github.com/dblock/syntax/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('0f4fe45d8dca5cbc6bb0870de5f23aa4d2f518c320dcb38f24b8d603abf16e3a')

prepare() {
  cd syntax-$pkgver
  sed 's/, "< 11.0.0"//' -i syntax.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd syntax-$pkgver
  gem build syntax.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    syntax-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd syntax-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd syntax-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
